package com.myjavalab.thread;

public class ShutdownHook {
	public static void main(String[] args) {
		System.out.println("main : begin");
		Runtime.getRuntime().addShutdownHook(
				new Thread() {
					public void run() {
						while(true) {
							System.out.println("*****");
							System.out.println(Thread.currentThread().getName() + " : shutdown hook!");
							System.out.println("*****");							
							try {
								Thread.sleep(1000);
							} catch (InterruptedException e) {
								
							}
						}
					}
				});
		System.out.println("main sleeping...");
		try {
			Thread.sleep(3000);
		}catch (InterruptedException e) {
		}
		System.out.println("main : exit");
		System.exit(0);
		System.out.println("main : end");   //never execute this 
	}
}
